package com.example.chenduoyun.safe.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.chenduoyun.safe.R;

/**
 * @author by created chen cloudy 2018/9/7 14:32
 **/

public class SettingItemView extends RelativeLayout {
    private TextView tv_title, tv_des;
    private CheckBox cd_box;
    private String NAMESPACE = "http://schemas.android.com/apk/res/com.example.chenduoyun.safe";
    private String mDesoff,mDestitle,mDeson;
    public SettingItemView(Context context) {
        this(context, null);
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View.inflate(context, R.layout.setting_item_view, this);
        tv_title = findViewById(R.id.tv_title);
        tv_des = findViewById(R.id.tv_des);
        cd_box = findViewById(R.id.cb_box);
        initAttrs(attrs);
        tv_title.setText(mDestitle);
    }

    /**
     * 返回自定义属性的属性值
     *
     * @param attrs
     */
    private void initAttrs(AttributeSet attrs) {
        mDestitle = attrs.getAttributeValue(NAMESPACE, "destitle");
        mDesoff = attrs.getAttributeValue(NAMESPACE, "desoff");
        mDeson = attrs.getAttributeValue(NAMESPACE, "deson");
    }

    public boolean isCheck() {
        return cd_box.isChecked();
    }

    public void setCheck(boolean isCheck) {
        cd_box.setChecked(isCheck);
        if (isCheck) {
            tv_des.setText(mDeson);
        } else {
            tv_des.setText(mDesoff);
        }
    }


}
